package com.tron.sync.config;

import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.web.client.RestTemplate;

/**
 * 迁移数据已经没有在使用
 */
//@Configuration
public class ElasticSearchConfig {
    @Value("${fromElk}")
    private String fromElk;
    @Value("${fromUsername}")
    private String fromUsername;
    @Value("${fromPassword}")
    private String fromPassword;

    @Bean
    public ElasticsearchRestTemplate elasticsearchRestTemplate(){
        return  new ElasticsearchRestTemplate(elasticsearchClient(fromElk.split(","), fromUsername, fromPassword));
    }
    private RestHighLevelClient elasticsearchClient(String[] hostAndPorts, String username, String password) {
        final ClientConfiguration clientConfiguration = ClientConfiguration.builder()
                .connectedTo(hostAndPorts)
                .withBasicAuth(username, password)
                .build();
        return RestClients.create(clientConfiguration).rest();
    }

    @Bean
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }
}
